<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>系统购买</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <link rel="stylesheet" href="${ctx}/css/ui/crowdfund/analyze_list.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        .xianxia {
            text-decoration: underline;
            color: orange;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" id="myForm" method="post" action="${ctx}/serviceOrder/list.do">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">下单者</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="memberName" class="layui-input" autocomplete="off"
                                           value="${input.memberName}"
                                           placeholder="请输入查询订单下单者"/>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">系统类型</label>
                                <div class="layui-input-inline">
                                    <select name="systemType">
                                        <option value="">全部</option>
                                        <option value="1" ${packageMember.systemType == 1 ? 'selected' : ''}>社群</option>
                                        <option value="2" ${packageMember.systemType == 2 ? 'selected' : ''}>众筹</option>
                                    </select>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">支付类型</label>
                                <div class="layui-input-inline">
                                    <select name="payWay">
                                        <option value="">全部</option>
                                        <option value="0" ${packageMember.payWay == 0 ? 'selected' : ''}>支付宝</option>
                                        <option value="1" ${packageMember.payWay == 1 ? 'selected' : ''}>微信</option>
                                        <option value="3" ${packageMember.payWay == 3 ? 'selected' : ''}>线下转账</option>
                                    </select>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item-inline">
                                <label class="search-form-lable">订单状态</label>
                                <div class="layui-input-inline">
                                    <select name="payStatus">
                                        <option value="">全部</option>
                                        <option value="1" ${packageMember.payStatus == 1 ? 'selected' : ''}>待支付</option>
                                        <option value="2" ${packageMember.payStatus == 2 ? 'selected' : ''}>支付成功
                                        </option>
                                    </select>
                                </div>
                            </li>
                            <li class="form-item-inline" style="margin-left: -123px;">
                                <label class="search-form-lable">审核状态</label>
                                <div class="layui-input-inline">
                                    <select name="auditStatus">
                                        <option value="">全部</option>
                                        <option value="1" ${packageMember.auditStatus == 1 ? 'selected' : ''}>待审核
                                        </option>
                                        <option value="2" ${packageMember.auditStatus == 2 ? 'selected' : ''}>审核成功
                                        </option>
                                        <option value="3" ${packageMember.auditStatus == 3 ? 'selected' : ''}>审核失败
                                        </option>
                                    </select>
                                </div>
                            </li>
                            <li class="form-item-inline" style="margin-left: -123px;">
                                <label class="search-form-lable">是否有效</label>
                                <div class="layui-input-inline">
                                    <select name="auditStatus">
                                        <option value="">全部</option>
                                        <option value="1" ${packageMember.status == 1 ? 'selected' : ''}>有效
                                        </option>
                                        <option value="2" ${packageMember.status == 2 ? 'selected' : ''}>失效
                                        </option>
                                    </select>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">下单时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="my-act-list-content">
                <ul class="num">
                    <div class="r">
                        <li style="cursor: pointer;" class="r"><a class="layui-btn layui-btn-danger layui-btn-sm"
                                                                  id="btnExport">导出EXCEL</a></li>
                    </div>
                    <p class="cl"></p>
                </ul>
                <div class="cl">
                    <table id="order_table" class="layui-table">
                        <colgroup>
                            <col style="width: 20%">
                            <col>
                            <col>
                            <col width="135">
                            <col width="120">
                            <col width="120">
                            <col width="180">
                            <col width="120">
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>订单名称</th>
                            <th>下单者</th>
                            <th>金额（元）</th>
                            <th>服务抵扣（元）</th>
                            <th>支付方式</th>
                            <th>状态</th>
                            <th>更新时间</th>
                            <th>是否有效</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="packageMember" items="${list}">
                            <tr>
                                <td>${packageMember.systemType == 1? '社群':'众筹'}系统 —— ${packageMember.packageName}</td>
                                <td class="table-member"
                                    onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${packageMember.memberId}','400px','470px')">
                                    <div class="member-cell">
                                        <div class="member-logo" style="background-image: <c:if
                                                test="${packageMember.memberLogo != null}">url('${packageMember.memberLogo}?imageMogr2/auto-orient/crop/126x126'),</c:if>url(${ctx}/image/def_user_logo.png)"></div>
                                        <div class="member-name ellipsis-1">
                                            <a class="blue" title="${packageMember.memberName}"
                                               style="cursor: pointer;">${packageMember.memberName}</a>
                                        </div>
                                    </div>
                                </td>
                                <td>${packageMember.price}</td>
                                <td>${packageMember.deductionAmount}</td>
                                <td>
                                    <c:if test="${packageMember.payWay == 0}">支付宝</c:if>
                                    <c:if test="${packageMember.payWay == 1}">微信支付</c:if>
                                    <c:if test="${packageMember.payWay == 3}"><a
                                            href="javascript:getRemittanceInfo('${packageMember.id}')" class="xianxia">线下转账</a></c:if>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${packageMember.auditStatus == 1}">
                                            待审核
                                        </c:when>
                                        <c:when test="${packageMember.auditStatus == 2}">
                                            审核成功
                                        </c:when>
                                        <c:when test="${packageMember.auditStatus == 3}">
                                            审核失败
                                        </c:when>
                                        <c:when test="${packageMember.payStatus == 1}">
                                            待支付
                                        </c:when>
                                        <c:when test="${packageMember.payStatus == 2}">
                                            支付成功
                                        </c:when>
                                        <c:when test="${packageMember.payStatus > 2}">
                                            其他
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td><fmt:formatDate value="${packageMember.updateDate}"
                                                    pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                <td>
                                    <c:choose>
                                        <c:when test="${packageMember.status == 1}">
                                            有效
                                        </c:when>
                                        <c:when test="${packageMember.status == 2}">
                                            无效
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td class="tb-opts">
                                    <div class="comm-opts">
                                        <c:if test="${packageMember.auditStatus == 1 && packageMember.status == 1}">
                                            <a href="javascript:audit('${packageMember.id}','1')"
                                               class="green">通过</a>
                                            <a href="javascript:audit('${packageMember.id}','2')"
                                               class="red">拒绝</a>
                                        </c:if>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <div id="page_content" class="page-container"></div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
    <div id="orderInfo" style="padding: 10px"></div>
</div>
<script type="text/html" id="order_template">
    <table class="layui-table" lay-skin="nob">
        <tbody>
        <tr>
            <td>银行账号</td>
            <td>{{ d.bankAccount }}</td>
        </tr>
        <tr>
            <td>开户名</td>
            <td>{{ d.accountName }}</td>
        </tr>
        <tr>
            <td>开户行</td>
            <td>{{ d.openingBank }}</td>
        </tr>
        <tr>
            <td>付款金额</td>
            <td>￥{{ d.price }}</td>
        </tr>
        </tbody>
    </table>
</script>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    var laytpl = null;
    loadPageNew({elem: 'page_content', totalCount: '${page.totalCount}', limit: '${page.limit}', page: '${page.page}'});
    $(function () {
        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        layui.use(['laydate', 'laytpl'], function () {
            laytpl = layui.laytpl;

            var laydate = layui.laydate;
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        })


        $("#btnExport").click(function () {
            layer.confirm('确认要导出Excel吗?', {
                icon: 3,
                title: '系统提示'
            }, function (index) {
                var url = "${ctx}/serviceOrder/exportSystemPayOrder.do";
                //loading层
                var loadIndex = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
                $.post(url, $("#myForm").serialize(), function (res) {
                    top.layer.close(loadIndex);
                    if (res.success) {
                        window.location.href = res.data;
                    } else {
                        util.layerMsgError(res.description)
                    }
                });
                top.layer.close(index);
            });
        });
    })

    function getRemittanceInfo(packageMemberId) {
        //loading层
        var loadIndex = layer.load(1, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
        $.get('${ctx}/serviceOrder/remittanceInfo.do', {'packageMemberId': packageMemberId}, function (res) {
            layer.close(loadIndex);
            if (res.success) {
                var content = $("#orderInfo");
                $(content).html("");
                var getTpl = $("#order_template").html();
                laytpl(getTpl).render(res.data, function (html) {
                    content.append(html);
                });

                var setPayIndex = layer.open({
                    type: 1,
                    area: ['450px', '300px'],
                    title: '查看汇款凭证',
                    content: $("#orderInfo"),
                    btn: ['关闭'],
                    success: function () { // 弹出后回调

                    },
                    end: function () { // 销毁后回调
                        $("#orderInfo").html('');
                    },
                    yes: function () { // 确定按钮
                        layer.close(setPayIndex);
                    }
                });
            }
        })
    }

    function audit(id, sign) {
        var str = '通过';
        if (sign == '2') {
            str = '拒绝';
        }
        layer.confirm('确定要<span  style="color: red">' + str + '</span>当前系统购买订单吗？', {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            $.post("${ctx}/serviceOrder/audit.do", {
                id: id,
                sign: sign
            }, function (data) {
                if (data.success) {
                    util.layerMsgSuccess("审核成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerMsgError("审核失败")
                }
            });
        });
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '服务订购',
            curr: true
        }],
        info: '<span class="f14 gray">官方咨询电话：4008-771-663</span>'
    });
</script>
</body>
</html>